package com.ds.lens.flink.monitor.monitorjob.function.detector;

import com.ds.lens.data.common.constant.MonitorStateEnum;
import com.ds.lens.data.common.document.dto.MonitorEvent;
import com.ds.lens.flink.monitor.common.bo.MonitorDefinition;
import com.ds.lens.flink.monitor.common.BuilderUtil;
import com.ds.lens.flink.monitor.common.bo.Metric;
import org.springframework.util.CollectionUtils;

import javax.persistence.Transient;

public class NoDataDetector implements MonitorEventDetector {
    @Transient
    private MonitorDefinition definition;

    @Override
    public MonitorStateEnum getMonitorState() {
        return MonitorStateEnum.NO_DATA;
    }

    @Override
    public MonitorEvent detect(Metric metric) {
        if (CollectionUtils.isEmpty(metric.getValues())) {
            return BuilderUtil.buildMonitorEvent(definition, metric, null, null, MonitorStateEnum.NO_DATA);
        } else {
            return null;
        }
    }

    @Override
    public void setDefinition(MonitorDefinition definition) {
        this.definition = definition;
    }
}
